package com.zhongketech.sunflower.view;

import android.content.Context;
import android.widget.ArrayAdapter;


public class LogUpdate {


	private static LogUpdate instance = null;

	private Context context = null;
	private ArrayAdapter<String> arrayAdapter = null;

	private int MAX_LOG_COUNT = 100;
	//private List<String> logString = new ArrayList<String>();


	private LogUpdate()
	{

	}

	public static LogUpdate getInstance(Context c)
	{   
		if(null == instance || c != instance.context)
		{
			instance = new LogUpdate();
			instance.context = c;
			instance.init();

		}

		return instance;   
	}

	private void init()
	{
		arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
	}

	public ArrayAdapter<String> getAdapter()
	{
		return arrayAdapter;
	}

	public void update(String log,int level)
	{
		arrayAdapter.add(log);

			
		arrayAdapter.notifyDataSetChanged();
		if(MAX_LOG_COUNT < arrayAdapter.getCount())
		{
			arrayAdapter.clear();
		}
	}
}
